package com.junyidao.game.controller;

import com.junyidao.game.core.annotation.Action;
import com.junyidao.game.pojo.PCode;
import com.junyidao.game.pojo.TMsgSended;
import com.junyidao.game.service.CodeService;
import com.junyidao.game.service.MsgDetailService;
import com.junyidao.game.service.MsgSendedService;
import com.junyidao.game.vo.MsgSendedVo;
import com.junyidao.game.vo.MsgSendingVo;
import com.sun.org.apache.regexp.internal.RE;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;
import java.util.Map;

/**
 * 个人中心：消息查看
 * Created by zzh on 2016/8/28.
 */
@Controller
@RequestMapping("/userMessages")
public class UserMessagesController extends BaseController {

    @Autowired
    private CodeService codeService;

    @Autowired
    private MsgDetailService msgDetailService;

    @Autowired
    private MsgSendedService msgSendedService;

    @RequestMapping
    @Action(desc = "消息查看页面")
    public ModelAndView list() {
        ModelAndView result = new ModelAndView("system/user_messages_list");
        List<PCode> messagesType = codeService.select("MessagesType");
        result.addObject("messagesType", messagesType);
        return result;
    }

    @ResponseBody
    @RequestMapping(value = "/listMessages")
    @Action(desc = "获取消息列表", sysPriv = false)
    public Map<String, Object> listMessages(MsgSendedVo vo) {
        Map<String, Object> ret = msgDetailService.listMessages(vo);
        return resultSucess(ret);
    }

    @ResponseBody
    @RequestMapping(value = "/readMsgAll")
    @Action(desc = "批量设置兄消息为已阅", sysPriv = false)
    public Map<String, Object> readMsgAll(String ids) {
        msgDetailService.readMsgAll(ids);
        return resultSucess(null);
    }

    @ResponseBody
    @RequestMapping(value = "/delMsgAll")
    @Action(desc = "批量设置兄消息为已阅", sysPriv = false)
    public Map<String, Object> delMsgAll(String ids) {
        msgDetailService.delMsgAll(ids);
        return resultSucess(null);
    }

    @RequestMapping(value = "/detail")
    @Action(desc = "消息详情页面")
    public ModelAndView detail(Integer msgId) {
        ModelAndView result = new ModelAndView("system/user_messages_detail");
        MsgSendedVo msg = msgSendedService.getById(msgId);
        result.addObject("msg", msg);
        return result;
    }

    @ResponseBody
    @RequestMapping(value = "/forwardMsg")
    @Action(desc = "转发消息")
    public Map<String, Object> forwardMsg(String ids, String msgIds, String forwardType) {
        msgDetailService.forwardMsg(ids, msgIds, forwardType);
        return resultSucess(null);
    }

}
